// import com.alibaba.druid.DbType;
// import com.alibaba.druid.sql.ast.*;
// import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "SQLDropSynonymStatement.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/instanceof.h"
#include "../expr/SQLPropertyExpr.h"

SQLDropSynonymStatement::SQLDropSynonymStatement()
{
}

SQLDropSynonymStatement::SQLDropSynonymStatement(DbType_ptr dbType)
    : SQLStatementImpl(dbType)
{
}

// @Override
void SQLDropSynonymStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLDropSynonymStatement)))
  {
    acceptChild(visitor, name);
  }
  visitor->endVisit(SharedObject(SQLDropSynonymStatement));
}

// @Override
SQLObject_list_ptr SQLDropSynonymStatement::getChildren()
{
  SQLObject_list_ptr children = std::make_shared<std::list<SQLObject_ptr>>();
  if (name != nullptr)
  {
    children->push_back(name);
  }
  return children;
}

SQLName_ptr SQLDropSynonymStatement::getName()
{
  return name;
}

void SQLDropSynonymStatement::setName(SQLName_ptr name)
{
  this->name = name;
}

BOOL_ptr SQLDropSynonymStatement::isIfExists()
{
  return ifExists;
}

void SQLDropSynonymStatement::setIfExists(BOOL_ptr ifExists)
{
  this->ifExists = ifExists;
}

string_ptr SQLDropSynonymStatement::getSchema()
{
  SQLName_ptr name = getName();
  if (name == nullptr)
  {
    return nullptr;
  }

  if (instanceof <SQLName, SQLPropertyExpr>(name))
  {
    return (std::dynamic_pointer_cast<SQLPropertyExpr>(name))->getOwnernName();
  }

  return nullptr;
}

BOOL_ptr SQLDropSynonymStatement::isPublic()
{
  return isPublic_;
}

void SQLDropSynonymStatement::setPublic(BOOL_ptr aPublic)
{
  isPublic_ = aPublic;
}

BOOL_ptr SQLDropSynonymStatement::isForce()
{
  return force;
}

void SQLDropSynonymStatement::setForce(BOOL_ptr force)
{
  this->force = force;
}

BOOL_ptr SQLDropSynonymStatement::replace(SQLExpr_ptr expr, SQLExpr_ptr target)
{
  if (name == expr)
  {
    setName(std::dynamic_pointer_cast<SQLName>(target));
    return BOOL::TRUE;
  }

  return BOOL::FALSE;
}
